#include <bits/stdc++.h>
using namespace std;
int main()
{
	double p1[1010] = {0};
	double e2[1010] = {0};
	double c2[1010] = {0};
	int k, e, i, cnt = 0, t = 2;
	double c;
	while(t--){
		cin >> k;
		for(i = 0; i < k; i++){
			cin >> e >> c;
			p1[e] += c;
		}
	}
	for(i = 0; i < 1010; i++)
		if(p1[i] != 0.0){
			e2[cnt] = i;
			c2[cnt++] = p1[i];
		}
	cout << cnt;
	if(cnt != 0)
		cout << " ";
	for(i = cnt - 1; i >= 0; i--){
		printf("%.0f %.1f", e2[i], c2[i]);
		if(i != 0)
			cout << " ";
	}
	return 0;	
}
